package com.jrapider.manager.service.dept;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jrapider.compent.dict.DictData;
import com.jrapider.compent.dict.IDictProvider;
import com.jrapider.manager.data.mapper.SysDeptMapper;
import com.jrapider.manager.data.om.SysDept;
import com.jrapider.om.PageInfo;
import org.springframework.stereotype.Service;
import lombok.extern.log4j.Log4j2;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;


@Service
@Log4j2
public class SysDeptService extends ServiceImpl<SysDeptMapper, SysDept> implements IDictProvider {

    @Override
    public Set<String> supportCodes() {
        return new HashSet<String>(){{
            add("dept");
        }};
    }

    @Override
    public List<DictData> getDict(String code) {
        List<SysDept> list = baseMapper.selectList(new QueryWrapper<SysDept>().orderByAsc("code"));
        return list.stream().map(sysDept -> new DictData(){{
            setValue(sysDept.getCode());
            setCode(code);
            setNote(sysDept.getTitle());
        }}).collect(Collectors.toList());
    }

    @Override
    public List<DictData> getDict(String s, String s1, PageInfo pageInfo) {
        return getDict(s);
    }
}
